package com.ruoyi.ZdElectricityUsage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ZdElectricityUsage.domain.ZdElectricityUsage;
import com.ruoyi.ZdElectricityUsage.service.IZdElectricityUsageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用电信息Controller
 * 
 * @author 智电未来
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/ZdElectricityUsage/usage")
public class ZdElectricityUsageController extends BaseController
{
    @Autowired
    private IZdElectricityUsageService zdElectricityUsageService;

    /**
     * 查询用电信息列表
     */
    @PreAuthorize("@ss.hasPermi('ZdElectricityUsage:usage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZdElectricityUsage zdElectricityUsage)
    {
        startPage();
        List<ZdElectricityUsage> list = zdElectricityUsageService.selectZdElectricityUsageList(zdElectricityUsage);
        return getDataTable(list);
    }

    /**
     * 导出用电信息列表
     */
    @PreAuthorize("@ss.hasPermi('ZdElectricityUsage:usage:export')")
    @Log(title = "用电信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZdElectricityUsage zdElectricityUsage)
    {
        List<ZdElectricityUsage> list = zdElectricityUsageService.selectZdElectricityUsageList(zdElectricityUsage);
        ExcelUtil<ZdElectricityUsage> util = new ExcelUtil<ZdElectricityUsage>(ZdElectricityUsage.class);
        util.exportExcel(response, list, "用电信息数据");
    }

    /**
     * 获取用电信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ZdElectricityUsage:usage:query')")
    @GetMapping(value = "/{orderNumber}")
    public AjaxResult getInfo(@PathVariable("orderNumber") Long orderNumber)
    {
        return success(zdElectricityUsageService.selectZdElectricityUsageByOrderNumber(orderNumber));
    }

    /**
     * 新增用电信息
     */
    @PreAuthorize("@ss.hasPermi('ZdElectricityUsage:usage:add')")
    @Log(title = "用电信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZdElectricityUsage zdElectricityUsage)
    {
        return toAjax(zdElectricityUsageService.insertZdElectricityUsage(zdElectricityUsage));
    }

    /**
     * 修改用电信息
     */
    @PreAuthorize("@ss.hasPermi('ZdElectricityUsage:usage:edit')")
    @Log(title = "用电信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZdElectricityUsage zdElectricityUsage)
    {
        return toAjax(zdElectricityUsageService.updateZdElectricityUsage(zdElectricityUsage));
    }

    /**
     * 删除用电信息
     */
    @PreAuthorize("@ss.hasPermi('ZdElectricityUsage:usage:remove')")
    @Log(title = "用电信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderNumbers}")
    public AjaxResult remove(@PathVariable Long[] orderNumbers)
    {
        return toAjax(zdElectricityUsageService.deleteZdElectricityUsageByOrderNumbers(orderNumbers));
    }
}
